from rest_framework import serializers

from users.models import Spit


class SpitsModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Spit
        fields = '__all__'

    def create(self, validated_data):
        spit = super().create(validated_data)
        spit.visits += 1
        spit.save()
        try:
            commnet = Spit.objects.get(id=spit.parent_id)
            commnet.comment += 1
            commnet.save()
        except Exception as e:
            return spit
        return spit
